package com.sfc.spiderweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sfc.spiderweb.entity.param.AmazonTransferParam;
import com.sfc.spiderweb.entity.param.AmazonViolationDataParam;
import com.sfc.spiderweb.entity.po.AmazonTransfer;
import com.sfc.spiderweb.entity.po.AmazonViolationData;
import com.sfc.spiderweb.mapper.AmazonViolationDataMapper;
import com.sfc.spiderweb.service.AmazonViolationDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AmazonViolationDataServiceImpl extends ServiceImpl<AmazonViolationDataMapper, AmazonViolationData> implements AmazonViolationDataService {

    @Autowired
    private AmazonViolationDataMapper mapper;

    @Override
    public Page<AmazonViolationData> getPage(AmazonViolationDataParam param) {
        Page<AmazonViolationData> page = new Page<>(param.getCurrent(),param.getSize());
        QueryWrapper<AmazonViolationData> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(param.getAccount())){
            wrapper.lambda().eq(AmazonViolationData::getAccount, param.getAccount());
        }
        if (!StringUtils.isEmpty(param.getStartDownDate())){
            wrapper.lambda().ge(AmazonViolationData::getDownDate, param.getStartDownDate());
        }
        if (!StringUtils.isEmpty(param.getEndDownDate())){
            wrapper.lambda().le(AmazonViolationData::getDownDate, param.getEndDownDate());
        }
        if (!StringUtils.isEmpty(param.getState())){
            wrapper.lambda().eq(AmazonViolationData::getState, param.getState());
        }
        if (!StringUtils.isEmpty(param.getType())){
            wrapper.lambda().eq(AmazonViolationData::getType, param.getType());
        }
        wrapper.lambda().eq(AmazonViolationData::getStatus, "1");
        Page<AmazonViolationData> amazonTransferPage = mapper.selectPage(page, wrapper);
        return amazonTransferPage;
    }
}
